const app = getApp()

Page({
  data: {
    action:{},
    info:{},
    vip:[]
  },
  onLoad: function (options){
    app.getParam(options);
    this.setData({config:app.globalData.appConfig})
  },
  onShow: function () {
    app.loginState(()=>{
      this.getApi();
    },true)
  },
  //获取会员数据
  getApi:function () {
    //读取服务商会员以外的会员列表
    app.api().Get("api/v1/ais/vip/index",(rel) => {
      if(200 == rel.code){
        this.setData({
          vip:rel.data,
          action:rel.data[0]
        })
      }
    })
    //读取会员开通信息
    app.api().Get("api/v1/ais/user/vip",(rel) => {
      if(200 == rel.code){
        this.setData({
          info:rel.data
        })
      }
    })
  },
  onVip:function (e) {
    var index = e.currentTarget.dataset.index
    this.setData({
      action:this.data.vip[index]
    })
  },
  //支付开通
  doPayment:function (e) {
    wx.showLoading({title:'加载中',mask: true });
    app.api().Post('api/v1/ais/vip/regVip',{vip_id: this.data.action.id},(rel) => {
      wx.hideLoading();
      app.doWechatPay(rel.data,(res)=>{
        this.getApi();
      },(res) => {
        app.wxAlert('取消支付或开通失败')
      });
    })
  },
  //转发
  onShareAppMessage: function (e) {
    return {
      path: "/packageIndex/pages/vip/reg?ucode="+app.globalData.loginuser.ucode
    }
  }
})